package xyz.renyumeng.xkm.order.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.*;
import xyz.renyumeng.xkm.dto.order.UserOrderDto;
import xyz.renyumeng.xkm.dto.order.UserOrderPage;
import xyz.renyumeng.xkm.model.order.OrderInfo;
import xyz.renyumeng.xkm.order.service.OrderService;
import xyz.renyumeng.xkm.order.service.UserOrderService;
import xyz.renyumeng.xkm.result.Result;

import javax.annotation.Resource;
import java.util.List;

import static xyz.renyumeng.xkm.rabbitMQ.RabbitMqConstant.DELAY_PRODUCT_EXCHANGE;
import static xyz.renyumeng.xkm.rabbitMQ.RabbitMqConstant.DELAY_PRODUCT_ROUTING_KEY;

/**
 * @author renyumeng
 * @date Created in 21:44 2023/6/30
 */

@RestController
@RequestMapping("/user/order")
@Api(tags = "用户订单接口")
public class UserOrderController {

    @Resource
    private UserOrderService userOrderService;

    @Resource
    private OrderService orderService;

    @Resource
    private RabbitTemplate rabbitTemplate;


    @PostMapping("/page")
    @ApiOperation("分页查询一个用户的所有订单")
    public Result<List<UserOrderDto>> getUserOrderInfos(@RequestBody UserOrderPage userOrderPage) {
        return userOrderService.getUserOrderInfos(userOrderPage);
    }

    @PostMapping("/add")
    @ApiOperation(value = "用户添加订单")
    public Result<List<Long>> addOrders(@RequestBody List<OrderInfo> orderInfoList) {
        return orderService.addOrders(orderInfoList);
    }

    @GetMapping("/{userId}/{orderId}")
    @ApiOperation(value = "根据userId和orderId获取订单信息")
    public Result<UserOrderDto> getUserOrderInfo(@PathVariable Long userId, @PathVariable Long orderId) {
        return userOrderService.getUserOrderInfo(userId, orderId);
    }

    @DeleteMapping("/{orderId}")
    @ApiOperation("删除一个订单")
    public Result<Object> deleteOrder(@PathVariable Long orderId) {
        return userOrderService.deleteOrder(orderId);
    }

    // 查询用户未付款的订
    @GetMapping("/unpaid/{userId}")
    @ApiOperation("查询所有未付款的订单")
    public Result<List<OrderInfo>> getUnpaidOrder(@PathVariable Long userId){
        return userOrderService.getUnpaidOrder(userId);
    }

}
